import java.util.Enumeration;
import java.util.Vector;

import josx.platform.rcx.Button;
import josx.platform.rcx.Motor;
import josx.platform.rcx.Sensor;

public class Control {

	

	  public static void main (String[] arg)
	  {    
	      Thread t = new ControlThread();  t.start();

	      try{ Button.RUN.waitForPressAndRelease();} catch (Exception e) {}
	      System.exit(0);
	  }

}

class ControlThread extends Thread
{
	Vector stateMachines;
	
	public ControlThread()
	{
		stateMachines = new Vector();
	}
	
	public void run()
	{
		Vector urgentTransmissions = new Vector();
		Vector validTransmissions = new Vector();
		while(true)
		{
			Enumeration e = stateMachines.elements();
			NEWSTATE: while(e.hasMoreElements())
			{
				StateMachine current = (StateMachine)e.nextElement();
				
				while(current.isCommited())
				{
					
					break NEWSTATE;
				}
				
				urgentTransmissions.addAll(current.getUrgentTransitions());
				validTransmissions.addAll(current.getValidTransitions());
			}
			
			if(!urgentTransmissions.isEmpty())
			{
				/*
				 * pick random urgent trans, and handle it.
				 */
			} else if(!validTransmissions.isEmpty())
			{
				/*
				 * Vælg en valid transmission tilfældigt og udfør den.
				 */
			}
			else
			{
				/*
				 * Hvis ingen transitions, wait indtil notify af en sensor eller en statemachine
				 * hvis timer rammer.
				 */
			}
			
			urgentTransmissions.clear();
			validTransmissions.clear();
		}
	}
}

class Const
{
	public static final Motor[] feedBelt = new Motor[]{Motor.A, Motor.B};
	public static final Motor distBelt = Motor.C;
	
	public static final Sensor[] sensor = new Sensor[]{Sensor.S1, Sensor.S2};
}